import axios from 'axios';

// import store from '../store';
var https = axios.create({
        baseURL: 'https://book.youbaobao.xyz:18082',
        timeout: 10000,
        // headers:{}  //请求头添加token
    })
    //请求拦截器
https.interceptors.request.use(config => {
        return config

    }, error => {
        return Promise.reject(error)
    })
    //响应拦截器
https.interceptors.response.use(response => {
    const res = response.data;
    if (response.status === 200) {
        if (res.name && res.message) {
            return Promise.reject(new Error(res.message))
        }
        return res
    } else {
        const errMsg = res.msg || '请求失败'
        return Promise.reject(new Error(errMsg))
    }
}, error => {
    return Promise.reject(error);
})

export default https